package com.example.router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.tencent.mmkv.MMKV

/**
 * 页面路由参数拦截器
 * 用于页面追踪
 */
@Interceptor(priority = 4, name = "路由参数拦截器")
class RouteParamInterceptor:IInterceptor {
    private lateinit var mContent:Context
    override fun init(context: Context?) {
        context?.let {
            mContent=it
        }
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //获取Token
        val traceId=MMKV.defaultMMKV().decodeString("traceId","")
        if (!traceId.isNullOrEmpty()){
            postcard?.withString("traceId",traceId)
        }
        //postcard?.navigation()
        callback?.onContinue(postcard)
    }
}